from OCC.Core.BRepBndLib import brepbndlib_Add
from OCC.Core.BRepMesh import BRepMesh_IncrementalMesh
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox, BRepPrimAPI_MakeCylinder
from OCC.Core.Bnd import Bnd_Box
from OCC.Core.gp import gp_Pnt
from OCC.Display.OCCViewer import rgb_color

shape = BRepPrimAPI_MakeCylinder(30, 60,1).Shape()

# 获取包围盒
bbox = Bnd_Box() # 首先创建一个空的包围盒
tol= 1e-4
bbox.SetGap(tol)
brepbndlib_Add(shape, bbox, True) # 将形状添加到包围盒中
XMin, YMin, ZMin, XMax, YMax, ZMax = bbox.Get() # 获取包围盒的信息
print(XMin, YMin, ZMin, XMax, YMax, ZMax)
# 绘制包围盒
xmin = XMin
xmax = XMax
xlen = XMax - XMin
ymin = YMin
ymax = YMax
ylen = YMax - YMin
zmin = ZMin
zmax = ZMax
zlen = ZMax - ZMin

center = gp_Pnt((XMax + XMin) / 2,
                     (YMax + YMin) / 2,
                     (ZMax + ZMin) / 2)
box = BRepPrimAPI_MakeBox(gp_Pnt(xmin,ymin,zmin),gp_Pnt(xmax,ymax,zmax)).Shape()


from OCC.Display.SimpleGui import init_display
display, start_display, add_menu, add_function_to_menu = init_display()
display.DisplayShape(shape)
display.DisplayShape(box,update=True,color=rgb_color(0,0,0.1),transparency=1)
start_display()
